<template>
  <div>
    <NavBar></NavBar>

    <div class="msg-content">
      <!-- <div v-if="msgList.length === 0" class="content-empty">
        <img src="../img/empty.png" />
        <div class="content-empty-text">暂无内容</div>
      </div> -->
      <div class="list">
        <van-list v-model="loading" :finished="finished" @load="onLoad">
          <template slot="finished" v-if="msgList.length !== 0">
            没有更多了
          </template>
          <template slot="finished" v-if="msgList.length === 0">
            <div class="content-empty">
              <img src="../img/empty.png" />
              <div class="content-empty-text">暂无内容</div>
            </div>
          </template>
          <div
            class="list-item"
            v-for="item in msgList"
            :key="item.index"
            @click="handleMenu(item)"
          >
            <div class="list-item-time">{{ item.sendTime }}</div>

            <div class="list-item-card">
              <van-badge :dot="item.readFlag === 'N'">
                <div
                  class="list-item-card-title flex-row flex-align-row flex-justify-between"
                >
                  <div>{{ item.messageTitle }}</div>
                </div>
                <div class="list-item-card-desc">
                  {{ item.messageContent }}
                </div>
                <div class="list-item-card-line"></div>
                <div
                  class="list-item-card-detail flex-row flex-align-center flex-justify-between"
                >
                  <div>查看详情</div>
                  <div>
                    <img
                      src="../img/arrow-left.png"
                      class="list-item-card-detail-img"
                    />
                  </div>
                </div>
              </van-badge>
            </div>
          </div>
        </van-list>
      </div>
    </div>
  </div>
</template>
<script>
import NavBar from '@/components/h5header'
import API from '@/services/h5/msg'
export default {
  components: { NavBar },
  data() {
    return {
      curPage: 0,
      length: 10,
      msgList: [],
      loading: false,
      finished: false
    }
  },
  created() {
    this.onLoad()
  },
  methods: {
    async onLoad() {
      this.loading = true
      this.finished = false
      this.curPage += 1
      let params = {
        curPage: this.curPage,
        length: this.length,
        messageType: this.$route.query.messageType
      }
      const res = await API.getMsgByType(params)
      if (res && res.data && res.data.code === 1000) {
        this.msgList = this.msgList.concat(res.data.data.list)
        if (this.msgList.length < res.data.data.count) {
          this.loading = false
        } else {
          this.loading = false
          this.finished = true
          return
        }
      } else {
        this.loading = false
        this.finished = true
      }
    },
    handleMenu(item) {
      const time = item.sendTime ? item.sendTime.split(' ') : ''
      this.$router.push({
        path: '/msgDetail',
        query: {
          id: item.id,
          sendData: !time.length ? '' : time[0],
          sendTime: !time.length ? '' : time[1]
        }
      })
    }
  }
}
</script>
<style scoped lang="less">
.msg-content {
  height: calc(100vh - 40px);
  background: #fafafa;
  overflow: scroll;
}
.content-empty {
  padding-top: 208.5px;
  text-align: center;
  &-text {
    font-size: 16px;
    color: #999;
  }
}
.list {
  padding-top: 15px;
  padding-bottom: 15px;
  .list-item-time {
    text-align: center;
    font-size: 13px;
    color: #999;
  }
  .list-item-card {
    margin: 15px;
    background: #fff;
    border-radius: 4px;
    box-shadow: rgba(0, 0, 0, 0.05) 0 0 7px 0;
    padding: 20px 15px 13px 15px;
    &-title {
      font-size: 15px;
      color: #333;
      font-weight: bold;
    }
    &-readFlag {
      font-size: 12px;
      padding: 1px 5px;
      font-weight: normal;
      color: @c-color-primary;
      border: 1px solid @c-color-primary;
      border-radius: 5px;
    }
    &-desc {
      font-size: 13px;
      color: #999;
      margin-top: 10px;
      overflow: hidden;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-line-clamp: 2;
      line-clamp: 2;
      -webkit-box-orient: vertical;
    }
    &-line {
      width: 316px;
      border-bottom: 1px dashed #f0f0f0;
      margin-top: 14.5px;
    }
    &-detail {
      margin-top: 12.5px;
      font-size: 13px;
      color: #333;
      &-img {
        width: 7px;
        height: 13px;
      }
    }
  }
}
</style>
